package com.zty.xiaomiadmin.server.Controller;

import com.zty.xiaomiadmin.server.Entity.PageResult;
import com.zty.xiaomiadmin.server.Entity.QueryPageBean;
import com.zty.xiaomiadmin.server.Entity.QueryPageBeanOrder;
import com.zty.xiaomiadmin.server.Entity.Result;
import com.zty.xiaomiadmin.server.Service.OrderService.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@CrossOrigin
@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/getOrders")
    private Result getOrder(@RequestBody QueryPageBeanOrder queryPageBean) throws IOException {
        try {
            PageResult pageRes = orderService.getOrder(queryPageBean);
            return new Result(200, "查询成功", pageRes);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500, "查询失败", null);
        }
    }


    @PostMapping("/editOrderStatusById")
    private Result editOrderStatusById(@RequestParam("orderNo") String orderNo) throws IOException {
        try {
            System.out.println(orderNo);
            orderService.editOrderStatusById(orderNo);
            return new Result(200, "修改成功", null);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(500, "修改失败", null);
        }
    }
}
